home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer 2.0 / Internet Surfer 2.0 (Wayzata Technology) (1996).iso / pc / text / mac / faqs.219 < prev    next >
Text File  |  1996-02-12  |  25KB  |  736 lines

  1. Frequently Asked Questions (FAQS);faqs.219
  2.  
  3.  
  4. Article-I.D.: cs.part9_723198982
  5. Expires: Thu, 14 Jan 1993 08:36:22 GMT
  6. References: <part1_723198982@cs.cmu.edu>
  7. Sender: news@cs.cmu.edu (Usenet News System)
  8. Followup-To: sci.cryonics
  9. Organization: School of Computer Science, Carnegie Mellon
  10. Lines: 110
  11. Approved: news-answers-request@MIT.Edu
  12. Supersedes: <part9_722195851@cs.cmu.edu>
  13. Nntp-Posting-Host: u.ergo.cs.cmu.edu
  14.  
  15. Archive-name: cryonics-faq/part9
  16.  
  17.              Section 9: Glossary
  18.  
  19. (You can fetch cryomsg "n" by sending mail to kqb@whscad1.att.com or
  20. to kevin.q.brown@att.com with the subject line "CRYOMSG n".  The index
  21. to this FAQ list is cryomsg "0018.1".)
  22.  
  23. The next three sections have definitions of cryonics vocabulary.  The
  24. list is divided (at the discretion of the editor) into words to use,
  25. words not to use, and words to use in jest.
  26.  
  27.                  Words to Use
  28.  
  29. CRFT has a glossary on pp. 57 - 58.
  30.  
  31. biostasis - Synonym for "suspension".
  32.  
  33. cardiac arrest - Cessation of heartbeat.
  34.  
  35. clinical death - A person is clinically dead if they are in cardiac
  36. arrest and their pupils do not contract when light is shined into them.
  37.  
  38. cryobiology - Biology at low temperatures.  This includes organ preservation.
  39.  
  40. cryogenics - Science in general at low temperatures.
  41.  
  42. cryonics - The practice of freezing people at the end of their natural
  43. lifespan, hoping for eventual reanimation.
  44.  
  45. information-theoretic death - A person has reached
  46. information-theoretic death if a healthy state of that person could
  47. not possibly be deduced from the current state.  The exact timing of
  48. information-theoretic death depends on presently unknown details of
  49. how the brain works.  The current best estimates put it several hours
  50. after clinical death.
  51.  
  52. ischemia - Damage to tissues due to oxygen deprivation.
  53.  
  54. legal death - A person is legally dead if a doctor has signed a death
  55. certificate with his or her name on it.  This tends to happen when the
  56. doctor believes that modern technology will not be able to restore
  57. them to health.  The criteria for legal death change with time.
  58.  
  59. neurosuspension - The practice of only freezing a person's head or
  60. brain.
  61.  
  62. revival - The process of restoring a clinically dead person to health.
  63.  
  64. suspension - The process of preserving a person for eventual revival,
  65. usually by freezing in liquid nitrogen.  This happens after legal
  66. death but hopefully before information-theoretic death.
  67.  
  68.                Words Not to Use
  69.  
  70. corpsicle - Pejorative synonym for "suspended person".
  71.  
  72. cryonicist - An ambiguous term.  1. One who studies or who tries to
  73. improve the process of freezing people for later revival.  Use
  74. "cryonics researcher" instead.  2. One who is interested in cryonics.
  75. Use "cryonics fan" instead, or perhaps "person interested in cryonics".
  76.  
  77. death - A vague term.  Use "legal death", "clinical death", or
  78. "information-theoretic death" instead.
  79.  
  80. deanimation - An ugly-sounding synonym for "clinical death".
  81.  
  82. reanimation - An ugly-sounding synonym for "revival".
  83.  
  84.              Words To Use In Jest
  85.  
  86. flexionally disabled - frozen stiff
  87.  
  88. metabolically disadvantaged - clinically dead
  89.  
  90. (Next five are from Alcor Indiana Newsletter #5 by Steve Bridge,
  91. cryomsgs 1148 and 1149.)
  92.  
  93. chronologically gifted - old
  94.  
  95. experientially enhanced - old
  96.  
  97. achieved an overall metabolic deficiency - died, possibly frozen
  98.  
  99. thermally challenged - frozen
  100.  
  101. assumed room temperature - died, not frozen (Attributed to Rush Limbaugh)
  102.  
  103.                    Credits
  104.  
  105. The following people contributed to this document.  Some of them
  106. contributed by posting messages to cryonet or sci.cryonics which I
  107. used.  They are listed in alphabetical order by last name.
  108.  
  109.   Steve Bridge <72320.1642@CompuServe.COM>
  110.   Kevin Brown <kqb@whscad1.att.com>
  111.   Tim Freeman <tsf@cs.cmu.edu>
  112.   Daniel Green <danielg@autodesk.com>
  113.   Steven B. Harris <71450.1773@CompuServe.COM>
  114.   Bryan Michael Kearney <bk1a+@ANDREW.CMU.EDU>
  115.   Simon Levy <LEVY%LENNY@Venus.YCC.Yale.Edu>
  116.   Lola McCrary <lola@lucid.com>
  117.   Perry E. Metzger <pmetzger@snark.shearson.com>
  118.   Micheal B. O'Neal <mike@engr.latech.edu>
  119.   Art Quaife <quaife@garnet.berkeley.edu>
  120.   Richard Schroeppel <rcs@cs.arizona.edu>
  121.   Ralph Whelan <alcor@cup.portal.com>
  122.   Brian Wowk <73337.2723@CompuServe.COM>
  123.  
  124. and one person on the cryonet mailing list who chose to remain anonymous.
  125. Xref: bloom-picayune.mit.edu comp.lang.c:62383 news.answers:4599
  126. Newsgroups: comp.lang.c,news.answers
  127. Path: bloom-picayune.mit.edu!adam.mit.edu!scs
  128. From: scs@adam.mit.edu (Steve Summit)
  129. Subject: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)
  130. Message-ID: <1992Dec15.160735.21337@athena.mit.edu>
  131. Followup-To: poster
  132. Sender: news@athena.mit.edu (News system)
  133. Supersedes: <1992Dec1.025558.25274@athena.mit.edu>
  134. Nntp-Posting-Host: adam.mit.edu
  135. Reply-To: scs@adam.mit.edu
  136. X-Archive-Name: C-faq/abridged
  137. Organization: none, at the moment
  138. Date: Tue, 15 Dec 1992 16:07:35 GMT
  139. X-Last-Modified: November 3, 1992
  140. Approved: news-answers-request@MIT.Edu
  141. Expires: Wed, 6 Jan 1993 00:00:00 GMT
  142. Lines: 944
  143.  
  144. Archive-name: C-faq/abridged
  145.  
  146. [Last modified November 3, 1992 by scs.]
  147.  
  148. This article contains minimal answers to the comp.lang.c frequently-
  149. asked questions list.  Please see the long version (posted on the
  150. first of each month, or see question 17.21) for more detailed
  151. explanations and references.
  152.  
  153.  
  154. Section 1. Null Pointers
  155.  
  156. 1.1:    What is this infamous null pointer, anyway?
  157.  
  158. A:    For each pointer type, there is a special value -- the "null
  159.     pointer" -- which is distinguishable from all other pointer
  160.     values and which is not the address of any object.
  161.  
  162. 1.2:    How do I "get" a null pointer in my programs?
  163.  
  164. A:    A constant 0 in a pointer context is converted into a null
  165.     pointer at compile time.  A "pointer context" is an
  166.     initialization, assignment, or comparison with one side a
  167.     variable or expression of pointer type, and (in ANSI standard C)
  168.     a function argument which has a prototype in scope declaring a
  169.     certain parameter as being of pointer type.  In other contexts
  170.     (function arguments without prototypes, or in the variable part
  171.     of variadic function calls) a constant 0 with an appropriate
  172.     explicit cast is required.
  173.  
  174. 1.3:    What is NULL and how is it #defined?
  175.  
  176. A:    NULL is simply a preprocessor macro, #defined as 0 (or
  177.     (void *)0), which is used (as a stylistic convention, in
  178.     preference to unadorned 0's) to generate null pointers,
  179.  
  180. 1.4:    How should NULL be #defined on a machine which uses a nonzero
  181.     bit pattern as the internal representation of a null pointer?
  182.  
  183. A:    The same as any other machine: as 0 (or (void *)0).  (The
  184.     compiler makes the translation, upon seeing a 0, not the
  185.     preprocessor.)
  186.  
  187. 1.5:    If NULL were defined as "(char *)0," wouldn't that make function
  188.     calls which pass an uncast NULL work?
  189.  
  190. A:    Not in general.  The problem is that there are machines which
  191.     use different internal representations for pointers to different
  192.     types of data.  A cast is still required to tell the compiler
  193.     which kind of null pointer is required, since it may be
  194.     different from (char *)0.
  195.  
  196. 1.6:    I use the preprocessor macro "#define Nullptr(type) (type *)0"
  197.     to help me build null pointers of the correct type.
  198.  
  199. A:    This trick, though valid, does not buy much.
  200.  
  201. 1.7:    Is the abbreviated pointer comparison "if(p)" to test for non-
  202.     null pointers valid?  What if the internal representation for
  203.     null pointers is nonzero?
  204.  
  205. A:    The construction "if(p)" works, regardless of the internal
  206.     representation of null pointers, because the compiler
  207.     essentially rewrites it as "if(p != 0)" and goes on to convert 0
  208.     into the correct null pointer.
  209.  
  210. 1.8:    If "NULL" and "0" are equivalent, which should I use?
  211.  
  212. A:    Either; the distinction is entirely stylistic.
  213.  
  214. 1.9:    But wouldn't it be better to use NULL (rather than 0) in case
  215.     the value of NULL changes, perhaps on a machine with nonzero
  216.     null pointers?
  217.  
  218. A:    No.  NULL is, and will always be, 0.
  219.  
  220. 1.10:    I'm confused.  NULL is guaranteed to be 0, but the null pointer
  221.     is not?
  222.  
  223. A:    A "null pointer" is a language concept whose particular internal
  224.     value does not matter.  A null pointer is requested in source
  225.     code with the character "0".  "NULL" is a preprocessor macro,
  226.     which is always #defined as 0 (or (void *)0).
  227.  
  228. 1.11:    Why is there so much confusion surrounding null pointers?  Why
  229.     do these questions come up so often?
  230.  
  231. A:    The fact that null pointers are represented both in source code,
  232.     and internally to most machines, as zero invites unwarranted
  233.     assumptions.  The use of a preprocessor macro (NULL) suggests
  234.     that the value might change later, or on some weird machine.
  235.  
  236. 1.12:    I'm still confused.  I just can't understand all this null
  237.     pointer stuff.
  238.  
  239. A:    A simple rule is, "Always use `0' or `NULL' for null pointers,
  240.     and always cast them when they are used as arguments in function
  241.     calls."
  242.  
  243. 1.13:    Given all the confusion surrounding null pointers, wouldn't it
  244.     be easier simply to require them to be represented internally by
  245.     zeroes?
  246.  
  247. A:    Such a requirement would accomplish little.
  248.  
  249. 1.14:    Seriously, have any actual machines really used nonzero null
  250.     pointers?
  251.  
  252. A:    Machines manufactured by Prime and by Honeywell-Bull, as well as
  253.     Symbolics Lisp Machines, have done so.
  254.  
  255.  
  256. Section 2. Arrays and Pointers
  257.  
  258. 2.1:    I had the definition char a[6] in one source file, and in
  259.     another I declared extern char *a.  Why didn't it work?
  260.  
  261. A:    The declaration extern char *a simply does not match the actual
  262.     definition.  Use extern char a[].
  263.  
  264. 2.2:    But I heard that char a[] was identical to char *a.
  265.  
  266. A:    Not at all.  Arrays are not pointers.  A reference like x[3]
  267.     generates different code depending on whether x is an array or a
  268.     pointer.
  269.  
  270. 2.3:    So what is meant by the "equivalence of pointers and arrays"
  271.     in C?
  272.  
  273. A:    An lvalue of type array-of-T which appears in an expression
  274.     decays into a pointer to its first element; the type of the
  275.     resultant pointer is pointer-to-T.  So for an array a and
  276.     pointer p, you can say "p = a;" and then p[3] and a[3] will
  277.     access the same element.
  278.  
  279. 2.4:    Why are array and pointer declarations interchangeable as
  280.     function formal parameters?
  281.  
  282. A:    Since functions can never receive arrays as parameters, any
  283.     parameter declarations which "look like" arrays are treated by
  284.     the compiler as if they were pointers.
  285.  
  286. 2.5:    Why doesn't sizeof properly report the size of an array which is
  287.     a parameter to a function?
  288.  
  289. A:    The sizeof operator reports the size of the pointer parameter
  290.     which the function actually receives.
  291.  
  292. 2.6:    Someone explained to me that arrays were really just constant
  293.     pointers.
  294.  
  295. A:    An array name is "constant" in that it cannot be assigned to,
  296.     but an array is _not_ a pointer.
  297.  
  298. 2.7:    I came across some "joke" code containing the "expression"
  299.     5["abcdef"] .  How can this be legal C?
  300.  
  301. A:    Yes, array subscripting is commutative in C.  The array
  302.     subscripting operation a[e] is defined as being equivalent to
  303.     *((a)+(e)).
  304.  
  305. 2.8:    My compiler complained when I passed a two-dimensional array to
  306.     a routine expecting a pointer to a pointer.
  307.  
  308. A:    The rule by which arrays decay into pointers is not applied
  309.     recursively.  An array of arrays (i.e. a two-dimensional array
  310.     in C) decays into a pointer to an array, not a pointer to a
  311.     pointer.
  312.  
  313. 2.9:    How do I declare a pointer to an array?
  314.  
  315. A:    Usually, you don't want to.  Consider using a pointer to one of
  316.     the array's elements instead.
  317.  
  318. 2.10:    How can I dynamically allocate a multidimensional array?
  319.  
  320. A:    It is usually best to allocate an array of pointers, and then
  321.     initialize each pointer to a dynamically-allocated "row."
  322.     See the full list for code samples.
  323.  
  324. 2.11:    Can I simulate a non-0-based array with a pointer?
  325.  
  326. A:    Not if the pointer points outside of the block of memory it is
  327.     intended to access.
  328.  
  329. 2.12:    I passed a pointer to a function which initialized it, but the
  330.     pointer in the caller was unchanged.
  331.  
  332. A:    The called function probably altered only the passed copy of the
  333.     pointer.
  334.  
  335. 2.13:    I have a char * pointer that happens to point to some ints, and
  336.     I want to step it over them.  Why doesn't "((int *)p)++;" work?
  337.  
  338. A:    In C, a cast operator is a conversion operator, and by
  339.     definition it yields an rvalue, which cannot be assigned to, or
  340.     incremented with ++.
  341.  
  342.  
  343. Section 3. Memory Allocation
  344.  
  345. 3.1:    Why doesn't the code "char *answer; gets(answer);" work?
  346.  
  347. A:    The pointer variable "answer" has not been set to point to any
  348.     valid storage.  The simplest way to correct this fragment is to
  349.     use a local array, instead of a pointer.
  350.  
  351. 3.2:    I can't get strcat to work.  I tried "char *s1 = "Hello, ",
  352.     *s2 = "world!", *s3 = strcat(s1, s2);" but I got strange
  353.     results.
  354.  
  355. A:    Again, the problem is that space for the concatenated result is
  356.     not properly allocated.
  357.  
  358. 3.3:    But the man page for strcat says that it takes two char *'s as
  359.     arguments.  How am I supposed to know to allocate things?
  360.  
  361. A:    In general, when using pointers you _always_ have to consider
  362.     memory allocation, at least to make sure that the compiler is
  363.     doing it for you.
  364.  
  365. 3.4:    I have a function that is supposed to return a string, but when
  366.     it returns to its caller, the returned string is garbage.
  367.  
  368. A:    Make sure that the memory to which the function returns a
  369.     pointer is correctly (i.e. not locally) allocated.
  370.  
  371. 3.5:    You can't use dynamically-allocated memory after you free it,
  372.     can you?
  373.  
  374. A:    No.  Some early man pages implied otherwise, but the claim is no
  375.     longer valid.
  376.  
  377. 3.6:    How does free() know how many bytes to free?
  378.  
  379. A:    The malloc/free package remembers the size of each block it
  380.     allocates and returns.
  381.  
  382. 3.7:    So can I query the malloc package to find out how big an
  383.     allocated block is?
  384.  
  385. A:    Not portably.
  386.  
  387. 3.8:    Is it legal to pass a null pointer as the first argument to
  388.     realloc()?
  389.  
  390. A:    ANSI C sanctions this usage, but several earlier implementations
  391.     do not support it.
  392.  
  393. 3.9:    Is it safe to use calloc's zero-fill guarantee for pointer and
  394.     floating-point values?
  395.  
  396. A:    No.
  397.  
  398. 3.10:    What is alloca and why is its use discouraged?
  399.  
  400. A:    alloca allocates memory which is automatically freed when the
  401.     function which called alloca returns.  alloca cannot be written
  402.     portably, is difficult to implement on machines without a stack,
  403.     and fails under certain conditions if implemented simply.
  404.  
  405.  
  406. Section 4. Expressions
  407.  
  408. 4.1:    Why doesn't the code "a[i] = i++;" work?
  409.  
  410. A:    The variable i is both referenced and modified in the same
  411.     expression.
  412.  
  413. 4.2:    Under my compiler, the code "int i = 7; printf("%d\n", i++ * i++);"
  414.     prints 49.  Regardless of the order of evaluation, shouldn't it
  415.     print 56?
  416.  
  417. A:    The operations implied by the postincrement and postdecrement
  418.     operators ++ and -- are performed at some time after the
  419.     operand's former values are yielded and before the end of the
  420.     expression, but not necessarily immediately after, or before
  421.     other parts of the expression are evaluated.
  422.  
  423. 4.3:    But what about the &&, ||, and comma operators?
  424.  
  425. A:    There is a special exception for those operators, (as well
  426.     as ?: ); left-to-right evaluation is guaranteed.
  427.  
  428. 4.4:    If I'm not using the value of the expression, should I use i++
  429.     or ++i to increment a variable?
  430.  
  431. A:    Since the two forms differ only in the value yielded, they are
  432.     entirely equivalent when only their side effect is needed.
  433.  
  434. 4.5:    Why doesn't the code "int a = 1000, b = 1000;
  435.     long int c = a * b;" work?
  436.  
  437. A:    You must manually cast one of the operands to (long).
  438.  
  439.  
  440. Section 5. ANSI C
  441.  
  442. 5.1:    What is the "ANSI C Standard?"
  443.  
  444. A:    In 1983, the American National Standards Institute commissioned
  445.     a committee, X3J11, to standardize the C language.  After a
  446.     long, arduous process, the committee's work was finally ratified
  447.     as an American National Standard, X3.159-1989, on December 14,
  448.     1989, and published in the spring of 1990.  The Standard has
  449.     also been adopted as ISO/IEC 9899:1990.
  450.  
  451. 5.2:    How can I get a copy of the Standard?
  452.  
  453. A:    Copies are available from the American National Standards
  454.     Institute in New York, or from Global Engineering Documents in
  455.     Irvine, CA.  See the unabridged list for addresses.
  456.  
  457. 5.3:    Does anyone have a tool for converting old-style C programs to
  458.     ANSI C, or for automatically generating prototypes?
  459.  
  460. A:    See the full list for details.
  461.  
  462. 5.4:    How do I keep the ANSI "stringizing" preprocessing operator from
  463.     stringizing the macro's name rather than its value?
  464.  
  465. A:    You must use a two-step #definition to force the macro to be
  466.     expanded as well as stringized.
  467.  
  468. 5.5:    What's the difference between "char const *p" and
  469.     "char * const p"?
  470.  
  471. A:    The former is a pointer to a constant character; the latter is a
  472.     constant pointer to a character.
  473.  
  474. 5.6:    My ANSI compiler complains about a mismatch when it sees
  475.  
  476.         extern int func(float);
  477.  
  478.         int func(x)
  479.         float x;
  480.         {...
  481.  
  482. A:    You have mixed the new-style prototype declaration
  483.     "extern int func(float);" with the old-style definition
  484.     "int func(x) float x;".  "Narrow" types are treated differently
  485.     according to which syntax is used.  The problem can be fixed by
  486.     using either new-style (prototype) or old-style syntax
  487.     consistently.
  488.  
  489. 5.7:    I'm getting strange syntax errors inside code which I've
  490.     #ifdeffed out.
  491.  
  492. A:    Under ANSI C, #ifdeffed-out text must still consist of "valid
  493.     preprocessing tokens."  This means that there must be no
  494.     unterminated comments or quotes (i.e. no single apostrophes),
  495.     and no newlines inside quotes.
  496.  
  497. 5.8:    Can I declare main as void, to shut off these annoying "main
  498.     returns no value" messages?
  499.  
  500. A:    No.
  501.  
  502. 5.9:    Why does the ANSI Standard not guarantee more than six monocase
  503.     characters of external identifier significance?
  504.  
  505. A:    The problem is older linkers which cannot be forced (by mere
  506.     words in a Standard) to upgrade.
  507.  
  508. 5.10:    What is the difference between memcpy and memmove?
  509.  
  510. A:    memmove offers guaranteed behavior if the source and destination
  511.     arguments overlap.
  512.  
  513. 5.11:    My compiler is rejecting the simplest possible test programs,
  514.     with all kinds of syntax errors.
  515.  
  516. A:    Perhaps it is a pre-ANSI compiler.
  517.  
  518. 5.12:    Why won't frobozz-cc, which claims to be ANSI compliant, accept
  519.     this code?
  520.  
  521. A:    Are you sure that the code being rejected doesn't rely on some
  522.     non-Standard extension?
  523.  
  524. 5.13:    What are #pragmas and what are they good for?
  525.  
  526. A:    The #pragma directive provides a single, well-defined "escape
  527.     hatch" which can be used for extensions.
  528.  
  529.  
  530. Section 6. C Preprocessor
  531.  
  532. 6.1:    How can I write a generic macro to swap two values?
  533.  
  534. A:    There is no good answer to this question.  The best all-around
  535.     solution is probably to forget about using a macro.
  536.  
  537. 6.2:    I have some old code that tries to construct identifiers with a
  538.     macro like "#define Paste(a, b) a/**/b ", but it doesn't work
  539.     any more.
  540.  
  541. A:    Try the ANSI token-pasting operator ##.
  542.  
  543. 6.3:    What's the best way to write a multi-statement cpp macro?
  544.  
  545. A:    #define Func() do {stmt1; stmt2; ... } while(0)  /* (no trailing ;) */
  546.  
  547. 6.4:    Is it acceptable for one header file to #include another?
  548.  
  549. A:    There has been considerable debate surrounding this question.
  550.  
  551. 6.5:    Does the sizeof operator work in preprocessor #if directives?
  552.  
  553. A:    No.
  554.  
  555. 6.6:    How can I use a preprocessor #if expression to detect
  556.     endianness?
  557.  
  558. A:    You probably can't.
  559.  
  560. 6.7:    I've got this tricky processing I want to do at compile time and
  561.     I can't figure out a way to get cpp to do it.
  562.  
  563. A:    Consider writing your own little special-purpose preprocessing
  564.     tool, instead.
  565.  
  566. 6.8:    How can I write a cpp macro which takes a variable number of
  567.     arguments?
  568.  
  569. A:    Here is one popular trick.  Note that the parentheses around
  570.     printf's argument list are in the macro call, not the
  571.     definition.
  572.  
  573.         #define DEBUG(args) (printf("DEBUG: "), printf args)
  574.  
  575.         if(n != 0) DEBUG(("n is %d\n", n));
  576.  
  577.  
  578. Section 7. Variable-Length Argument Lists
  579.  
  580. 7.1:    How can I write a function that takes a variable number of
  581.     arguments?
  582.  
  583. A:    Use the <stdarg.h> (or older <varargs.h>) header.
  584.  
  585. 7.2:    How can I write a function that takes a format string and a
  586.     variable number of arguments, like printf, and passes them to
  587.     printf to do most of the work?
  588.  
  589. A:    Use vprintf, vfprintf, or vsprintf.
  590.  
  591. 7.3:    How can I discover how many arguments a function was actually
  592.     called with?
  593.  
  594. A:    Any function which takes a variable number of arguments must be
  595.     able to determine from the arguments themselves how many of them
  596.     there are.
  597.  
  598. 7.4:    How can I write a function which takes a variable number of
  599.     arguments and passes them to some other function (which takes a
  600.     variable number of arguments)?
  601.  
  602. A:    In general, you cannot.
  603.  
  604. 7.5:    How can I call a function with an argument list built up at run
  605.     time?
  606.  
  607. A:    You can't.
  608.  
  609.  
  610. Section 8. Boolean Expressions and Variables
  611.  
  612. 8.1:    What is the right type to use for boolean values in C?  Why
  613.     isn't it a standard type?  Should #defines or enums be used for
  614.     the true and false values?
  615.  
  616. A:    C does not provide a standard boolean type, because picking one
  617.     involves a space/time tradeoff which is best decided by the
  618.     programmer.  The choice between #defines and enums is arbitrary
  619.     and not terribly interesting.
  620.  
  621. 8.2:    Isn't #defining TRUE to be 1 dangerous, since any nonzero value
  622.     is considered "true" in C?  What if a built-in boolean or
  623.     relational operator "returns" something other than 1?
  624.  
  625. A:    It is true (sic) that any nonzero value is considered true in C,
  626.     but this applies only "on input", i.e. where a boolean value is
  627.     expected.  When a boolean value is generated by a built-in
  628.     operator, it is guaranteed to be 1 or 0.  (This is _not_ true
  629.     for some library routines such as isalpha.)
  630.  
  631.  
  632. Section 9. Structs, Enums, and Unions
  633.  
  634. 9.1:    What is the difference between an enum and a series of
  635.     preprocessor #defines?
  636.  
  637. A:    At the present time, there is little difference.  The ANSI
  638.     standard states that enumerations are compatible with integral
  639.     types.
  640.  
  641. 9.2:    I heard that structures could be assigned to variables and
  642.     passed to and from functions, but K&R I says not.
  643.  
  644. A:    These operations are supported by all modern compilers.
  645.  
  646. 9.3:    How does struct passing and returning work?
  647.  
  648. A:    If you really need to know, see the unabridged list.
  649.  
  650. 9.4:    I have a program which works correctly, but dumps core after it
  651.     finishes.  Why?
  652.  
  653. A:    Check to see if a structure type declaration just before main is
  654.     missing its trailing semicolon, causing the compiler to believe
  655.     that main returns a structure.  See also question 17.15.
  656.  
  657. 9.5:    Why can't you compare structs?
  658.  
  659. A:    There is no reasonable way for a compiler to implement struct
  660.     comparison which is consistent with C's low-level flavor.
  661.  
  662. 9.6:    I came across some code that declared a structure with the last
  663.     member an array of one element, and then did some tricky
  664.     allocation to make the array act like it had several elements.
  665.     Is this legal and/or portable?
  666.  
  667. A:    The ANSI C standard allows it, but only implicitly.
  668.  
  669. 9.7:    How can I determine the byte offset of a field within a
  670.     structure?
  671.  
  672. A:    ANSI C defines the offsetof macro, which should be used if
  673.     available.
  674.  
  675. 9.8:    How can I access structure fields by name at run time?
  676.  
  677. A:    Build a table of names and offsets, using the offsetof() macro.
  678.  
  679. 9.9:    Why does sizeof report a larger size than I expect for a
  680.     structure type, as if there was padding at the end?
  681.  
  682. A:    The alignment of arrays of structures must be preserved.
  683.  
  684. 9.10:    How can I turn off structure padding?
  685.  
  686. A:    There is no standard method.
  687.  
  688. 9.11:    Can I initialize unions?
  689.  
  690. A:    ANSI Standard C allows an initializer for the first member.
  691.  
  692.  
  693. Section 10. Declarations
  694.  
  695. 10.1:    How do you decide which integer type to use?
  696.  
  697. A:    If you might need large values, use long.  Otherwise, if space
  698.     is very important, use short.  Otherwise, use int.
  699.  
  700. 10.2:    I can't seem to define a linked list node which contains a
  701.     pointer to itself.
  702.  
  703. A:    Structs in C can certainly contain pointers to themselves; the
  704.     discussion and example in section 6.5 of K&R make this clear.
  705.     Problems arise if an attempt is made to define (and use) a
  706.     typedef in the midst of such a declaration; avoid this.
  707.  
  708. 10.3:    How do I declare an array of pointers to functions returning
  709.     pointers to functions returning pointers to characters?
  710.  
  711. A:    char *(*(*a[5])())();
  712.     Using a chain of typedefs, or the cdecl program, makes these
  713.     declarations easier.
  714.  
  715. 10.4:    How can I declare a function that returns a pointer to a
  716.     function of its own type?
  717.  
  718. A:    You can't do it directly.
  719.  
  720. 10.5:    What's the best way to declare and define global variables?
  721.  
  722. A:    It is best to place the definition in some central .c file, with
  723.     an external declaration in a header file.
  724.  
  725. 10.6:    How do I initialize a pointer to a function?
  726.  
  727. A:    Use something like "extern int func(); int (*fp)() = func;" .
  728.  
  729. 10.7:    I've seen different methods used for calling through pointers to
  730.     functions.
  731.  
  732. A:    The extra parentheses and explicit * are now officially
  733.     optional, although some older implementations require them.
  734.  
  735.  
  736.